<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>debug.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_debug_debug.js.html">debug.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Logging and debugging utilities.
<a name="line17"></a> *
<a name="line18"></a> * @see ../demos/debug.html
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.debug&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.string&#39;);
<a name="line25"></a>goog.require(&#39;goog.structs.Set&#39;);
<a name="line26"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>/**
<a name="line30"></a> * Catches onerror events fired by windows and similar objects.
<a name="line31"></a> * @param {function(Object)} logFunc The function to call with the error
<a name="line32"></a> *    information.
<a name="line33"></a> * @param {boolean=} opt_cancel Whether to stop the error from reaching the
<a name="line34"></a> *    browser.
<a name="line35"></a> * @param {Object=} opt_target Object that fires onerror events.
<a name="line36"></a> */
<a name="line37"></a>goog.debug.catchErrors = function(logFunc, opt_cancel, opt_target) {
<a name="line38"></a>  var target = opt_target || goog.global;
<a name="line39"></a>  var oldErrorHandler = target.onerror;
<a name="line40"></a>  var retVal = !!opt_cancel;
<a name="line41"></a>
<a name="line42"></a>  // Chrome interprets onerror return value backwards (http://crbug.com/92062)
<a name="line43"></a>  // until it was fixed in webkit revision r94061 (Webkit 535.3). This
<a name="line44"></a>  // workaround still needs to be skipped in Safari after the webkit change
<a name="line45"></a>  // gets pushed out in Safari.
<a name="line46"></a>  // See https://bugs.webkit.org/show_bug.cgi?id=67119
<a name="line47"></a>  if (goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersion(&#39;535.3&#39;)) {
<a name="line48"></a>    retVal = !retVal;
<a name="line49"></a>  }
<a name="line50"></a>  target.onerror = function(message, url, line) {
<a name="line51"></a>    if (oldErrorHandler) {
<a name="line52"></a>      oldErrorHandler(message, url, line);
<a name="line53"></a>    }
<a name="line54"></a>    logFunc({
<a name="line55"></a>      message: message,
<a name="line56"></a>      fileName: url,
<a name="line57"></a>      line: line
<a name="line58"></a>    });
<a name="line59"></a>    return retVal;
<a name="line60"></a>  };
<a name="line61"></a>};
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>/**
<a name="line65"></a> * Creates a string representing an object and all its properties.
<a name="line66"></a> * @param {Object|null|undefined} obj Object to expose.
<a name="line67"></a> * @param {boolean=} opt_showFn Show the functions as well as the properties,
<a name="line68"></a> *     default is false.
<a name="line69"></a> * @return {string} The string representation of {@code obj}.
<a name="line70"></a> */
<a name="line71"></a>goog.debug.expose = function(obj, opt_showFn) {
<a name="line72"></a>  if (typeof obj == &#39;undefined&#39;) {
<a name="line73"></a>    return &#39;undefined&#39;;
<a name="line74"></a>  }
<a name="line75"></a>  if (obj == null) {
<a name="line76"></a>    return &#39;NULL&#39;;
<a name="line77"></a>  }
<a name="line78"></a>  var str = [];
<a name="line79"></a>
<a name="line80"></a>  for (var x in obj) {
<a name="line81"></a>    if (!opt_showFn &amp;&amp; goog.isFunction(obj[x])) {
<a name="line82"></a>      continue;
<a name="line83"></a>    }
<a name="line84"></a>    var s = x + &#39; = &#39;;
<a name="line85"></a>    /** @preserveTry */
<a name="line86"></a>    try {
<a name="line87"></a>      s += obj[x];
<a name="line88"></a>    } catch (e) {
<a name="line89"></a>      s += &#39;*** &#39; + e + &#39; ***&#39;;
<a name="line90"></a>    }
<a name="line91"></a>    str.push(s);
<a name="line92"></a>  }
<a name="line93"></a>  return str.join(&#39;\n&#39;);
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * Creates a string representing a given primitive or object, and for an
<a name="line99"></a> * object, all its properties and nested objects.  WARNING: If an object is
<a name="line100"></a> * given, it and all its nested objects will be modified.  To detect reference
<a name="line101"></a> * cycles, this method identifies objects using goog.getUid() which mutates the
<a name="line102"></a> * object.
<a name="line103"></a> * @param {*} obj Object to expose.
<a name="line104"></a> * @param {boolean=} opt_showFn Also show properties that are functions (by
<a name="line105"></a> *     default, functions are omitted).
<a name="line106"></a> * @return {string} A string representation of {@code obj}.
<a name="line107"></a> */
<a name="line108"></a>goog.debug.deepExpose = function(obj, opt_showFn) {
<a name="line109"></a>  var previous = new goog.structs.Set();
<a name="line110"></a>  var str = [];
<a name="line111"></a>
<a name="line112"></a>  var helper = function(obj, space) {
<a name="line113"></a>    var nestspace = space + &#39;  &#39;;
<a name="line114"></a>
<a name="line115"></a>    var indentMultiline = function(str) {
<a name="line116"></a>      return str.replace(/\n/g, &#39;\n&#39; + space);
<a name="line117"></a>    };
<a name="line118"></a>
<a name="line119"></a>    /** @preserveTry */
<a name="line120"></a>    try {
<a name="line121"></a>      if (!goog.isDef(obj)) {
<a name="line122"></a>        str.push(&#39;undefined&#39;);
<a name="line123"></a>      } else if (goog.isNull(obj)) {
<a name="line124"></a>        str.push(&#39;NULL&#39;);
<a name="line125"></a>      } else if (goog.isString(obj)) {
<a name="line126"></a>        str.push(&#39;&quot;&#39; + indentMultiline(obj) + &#39;&quot;&#39;);
<a name="line127"></a>      } else if (goog.isFunction(obj)) {
<a name="line128"></a>        str.push(indentMultiline(String(obj)));
<a name="line129"></a>      } else if (goog.isObject(obj)) {
<a name="line130"></a>        if (previous.contains(obj)) {
<a name="line131"></a>          // TODO(user): This is a bug; it falsely detects non-loops as loops
<a name="line132"></a>          // when the reference tree contains two references to the same object.
<a name="line133"></a>          str.push(&#39;*** reference loop detected ***&#39;);
<a name="line134"></a>        } else {
<a name="line135"></a>          previous.add(obj);
<a name="line136"></a>          str.push(&#39;{&#39;);
<a name="line137"></a>          for (var x in obj) {
<a name="line138"></a>            if (!opt_showFn &amp;&amp; goog.isFunction(obj[x])) {
<a name="line139"></a>              continue;
<a name="line140"></a>            }
<a name="line141"></a>            str.push(&#39;\n&#39;);
<a name="line142"></a>            str.push(nestspace);
<a name="line143"></a>            str.push(x + &#39; = &#39;);
<a name="line144"></a>            helper(obj[x], nestspace);
<a name="line145"></a>          }
<a name="line146"></a>          str.push(&#39;\n&#39; + space + &#39;}&#39;);
<a name="line147"></a>        }
<a name="line148"></a>      } else {
<a name="line149"></a>        str.push(obj);
<a name="line150"></a>      }
<a name="line151"></a>    } catch (e) {
<a name="line152"></a>      str.push(&#39;*** &#39; + e + &#39; ***&#39;);
<a name="line153"></a>    }
<a name="line154"></a>  };
<a name="line155"></a>
<a name="line156"></a>  helper(obj, &#39;&#39;);
<a name="line157"></a>  return str.join(&#39;&#39;);
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Recursively outputs a nested array as a string.
<a name="line163"></a> * @param {Array} arr The array.
<a name="line164"></a> * @return {string} String representing nested array.
<a name="line165"></a> */
<a name="line166"></a>goog.debug.exposeArray = function(arr) {
<a name="line167"></a>  var str = [];
<a name="line168"></a>  for (var i = 0; i &lt; arr.length; i++) {
<a name="line169"></a>    if (goog.isArray(arr[i])) {
<a name="line170"></a>      str.push(goog.debug.exposeArray(arr[i]));
<a name="line171"></a>    } else {
<a name="line172"></a>      str.push(arr[i]);
<a name="line173"></a>    }
<a name="line174"></a>  }
<a name="line175"></a>  return &#39;[ &#39; + str.join(&#39;, &#39;) + &#39; ]&#39;;
<a name="line176"></a>};
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * Exposes an exception that has been caught by a try...catch and outputs the
<a name="line181"></a> * error with a stack trace.
<a name="line182"></a> * @param {Object} err Error object or string.
<a name="line183"></a> * @param {Function=} opt_fn Optional function to start stack trace from.
<a name="line184"></a> * @return {string} Details of exception.
<a name="line185"></a> */
<a name="line186"></a>goog.debug.exposeException = function(err, opt_fn) {
<a name="line187"></a>  /** @preserveTry */
<a name="line188"></a>  try {
<a name="line189"></a>    var e = goog.debug.normalizeErrorObject(err);
<a name="line190"></a>
<a name="line191"></a>    // Create the error message
<a name="line192"></a>    var error = &#39;Message: &#39; + goog.string.htmlEscape(e.message) +
<a name="line193"></a>        &#39;\nUrl: &lt;a href=&quot;view-source:&#39; + e.fileName + &#39;&quot; target=&quot;_new&quot;&gt;&#39; +
<a name="line194"></a>        e.fileName + &#39;&lt;/a&gt;\nLine: &#39; + e.lineNumber + &#39;\n\nBrowser stack:\n&#39; +
<a name="line195"></a>        goog.string.htmlEscape(e.stack + &#39;-&gt; &#39;) +
<a name="line196"></a>        &#39;[end]\n\nJS stack traversal:\n&#39; + goog.string.htmlEscape(
<a name="line197"></a>            goog.debug.getStacktrace(opt_fn) + &#39;-&gt; &#39;);
<a name="line198"></a>    return error;
<a name="line199"></a>  } catch (e2) {
<a name="line200"></a>    return &#39;Exception trying to expose exception! You win, we lose. &#39; + e2;
<a name="line201"></a>  }
<a name="line202"></a>};
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * Normalizes the error/exception object between browsers.
<a name="line207"></a> * @param {Object} err Raw error object.
<a name="line208"></a> * @return {Object} Normalized error object.
<a name="line209"></a> */
<a name="line210"></a>goog.debug.normalizeErrorObject = function(err) {
<a name="line211"></a>  var href = goog.getObjectByName(&#39;window.location.href&#39;);
<a name="line212"></a>  if (goog.isString(err)) {
<a name="line213"></a>    return {
<a name="line214"></a>      &#39;message&#39;: err,
<a name="line215"></a>      &#39;name&#39;: &#39;Unknown error&#39;,
<a name="line216"></a>      &#39;lineNumber&#39;: &#39;Not available&#39;,
<a name="line217"></a>      &#39;fileName&#39;: href,
<a name="line218"></a>      &#39;stack&#39;: &#39;Not available&#39;
<a name="line219"></a>    };
<a name="line220"></a>  }
<a name="line221"></a>
<a name="line222"></a>  var lineNumber, fileName;
<a name="line223"></a>  var threwError = false;
<a name="line224"></a>
<a name="line225"></a>  try {
<a name="line226"></a>    lineNumber = err.lineNumber || err.line || &#39;Not available&#39;;
<a name="line227"></a>  } catch (e) {
<a name="line228"></a>    // Firefox 2 sometimes throws an error when accessing &#39;lineNumber&#39;:
<a name="line229"></a>    // Message: Permission denied to get property UnnamedClass.lineNumber
<a name="line230"></a>    lineNumber = &#39;Not available&#39;;
<a name="line231"></a>    threwError = true;
<a name="line232"></a>  }
<a name="line233"></a>
<a name="line234"></a>  try {
<a name="line235"></a>    fileName = err.fileName || err.filename || err.sourceURL ||
<a name="line236"></a>        // $googDebugFname may be set before a call to eval to set the filename
<a name="line237"></a>        // that the eval is supposed to present.
<a name="line238"></a>        goog.global[&#39;$googDebugFname&#39;] || href;
<a name="line239"></a>  } catch (e) {
<a name="line240"></a>    // Firefox 2 may also throw an error when accessing &#39;filename&#39;.
<a name="line241"></a>    fileName = &#39;Not available&#39;;
<a name="line242"></a>    threwError = true;
<a name="line243"></a>  }
<a name="line244"></a>
<a name="line245"></a>  // The IE Error object contains only the name and the message.
<a name="line246"></a>  // The Safari Error object uses the line and sourceURL fields.
<a name="line247"></a>  if (threwError || !err.lineNumber || !err.fileName || !err.stack) {
<a name="line248"></a>    return {
<a name="line249"></a>      &#39;message&#39;: err.message,
<a name="line250"></a>      &#39;name&#39;: err.name,
<a name="line251"></a>      &#39;lineNumber&#39;: lineNumber,
<a name="line252"></a>      &#39;fileName&#39;: fileName,
<a name="line253"></a>      &#39;stack&#39;: err.stack || &#39;Not available&#39;
<a name="line254"></a>    };
<a name="line255"></a>  }
<a name="line256"></a>
<a name="line257"></a>  // Standards error object
<a name="line258"></a>  return err;
<a name="line259"></a>};
<a name="line260"></a>
<a name="line261"></a>
<a name="line262"></a>/**
<a name="line263"></a> * Converts an object to an Error if it&#39;s a String,
<a name="line264"></a> * adds a stacktrace if there isn&#39;t one,
<a name="line265"></a> * and optionally adds an extra message.
<a name="line266"></a> * @param {Error|string} err  the original thrown object or string.
<a name="line267"></a> * @param {string=} opt_message  optional additional message to add to the
<a name="line268"></a> *     error.
<a name="line269"></a> * @return {Error} If err is a string, it is used to create a new Error,
<a name="line270"></a> *     which is enhanced and returned.  Otherwise err itself is enhanced
<a name="line271"></a> *     and returned.
<a name="line272"></a> */
<a name="line273"></a>goog.debug.enhanceError = function(err, opt_message) {
<a name="line274"></a>  var error = typeof err == &#39;string&#39; ? Error(err) : err;
<a name="line275"></a>  if (!error.stack) {
<a name="line276"></a>    error.stack = goog.debug.getStacktrace(arguments.callee.caller);
<a name="line277"></a>  }
<a name="line278"></a>  if (opt_message) {
<a name="line279"></a>    // find the first unoccupied &#39;messageX&#39; property
<a name="line280"></a>    var x = 0;
<a name="line281"></a>    while (error[&#39;message&#39; + x]) {
<a name="line282"></a>      ++x;
<a name="line283"></a>    }
<a name="line284"></a>    error[&#39;message&#39; + x] = String(opt_message);
<a name="line285"></a>  }
<a name="line286"></a>  return error;
<a name="line287"></a>};
<a name="line288"></a>
<a name="line289"></a>
<a name="line290"></a>/**
<a name="line291"></a> * Gets the current stack trace. Simple and iterative - doesn&#39;t worry about
<a name="line292"></a> * catching circular references or getting the args.
<a name="line293"></a> * @param {number=} opt_depth Optional maximum depth to trace back to.
<a name="line294"></a> * @return {string} A string with the function names of all functions in the
<a name="line295"></a> *     stack, separated by \n.
<a name="line296"></a> */
<a name="line297"></a>goog.debug.getStacktraceSimple = function(opt_depth) {
<a name="line298"></a>  var sb = [];
<a name="line299"></a>  var fn = arguments.callee.caller;
<a name="line300"></a>  var depth = 0;
<a name="line301"></a>
<a name="line302"></a>  while (fn &amp;&amp; (!opt_depth || depth &lt; opt_depth)) {
<a name="line303"></a>    sb.push(goog.debug.getFunctionName(fn));
<a name="line304"></a>    sb.push(&#39;()\n&#39;);
<a name="line305"></a>    /** @preserveTry */
<a name="line306"></a>    try {
<a name="line307"></a>      fn = fn.caller;
<a name="line308"></a>    } catch (e) {
<a name="line309"></a>      sb.push(&#39;[exception trying to get caller]\n&#39;);
<a name="line310"></a>      break;
<a name="line311"></a>    }
<a name="line312"></a>    depth++;
<a name="line313"></a>    if (depth &gt;= goog.debug.MAX_STACK_DEPTH) {
<a name="line314"></a>      sb.push(&#39;[...long stack...]&#39;);
<a name="line315"></a>      break;
<a name="line316"></a>    }
<a name="line317"></a>  }
<a name="line318"></a>  if (opt_depth &amp;&amp; depth &gt;= opt_depth) {
<a name="line319"></a>    sb.push(&#39;[...reached max depth limit...]&#39;);
<a name="line320"></a>  } else {
<a name="line321"></a>    sb.push(&#39;[end]&#39;);
<a name="line322"></a>  }
<a name="line323"></a>
<a name="line324"></a>  return sb.join(&#39;&#39;);
<a name="line325"></a>};
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/**
<a name="line329"></a> * Max length of stack to try and output
<a name="line330"></a> * @type {number}
<a name="line331"></a> */
<a name="line332"></a>goog.debug.MAX_STACK_DEPTH = 50;
<a name="line333"></a>
<a name="line334"></a>
<a name="line335"></a>/**
<a name="line336"></a> * Gets the current stack trace, either starting from the caller or starting
<a name="line337"></a> * from a specified function that&#39;s currently on the call stack.
<a name="line338"></a> * @param {Function=} opt_fn Optional function to start getting the trace from.
<a name="line339"></a> *     If not provided, defaults to the function that called this.
<a name="line340"></a> * @return {string} Stack trace.
<a name="line341"></a> */
<a name="line342"></a>goog.debug.getStacktrace = function(opt_fn) {
<a name="line343"></a>  return goog.debug.getStacktraceHelper_(opt_fn || arguments.callee.caller, []);
<a name="line344"></a>};
<a name="line345"></a>
<a name="line346"></a>
<a name="line347"></a>/**
<a name="line348"></a> * Private helper for getStacktrace().
<a name="line349"></a> * @param {Function} fn Function to start getting the trace from.
<a name="line350"></a> * @param {Array} visited List of functions visited so far.
<a name="line351"></a> * @return {string} Stack trace starting from function fn.
<a name="line352"></a> * @private
<a name="line353"></a> */
<a name="line354"></a>goog.debug.getStacktraceHelper_ = function(fn, visited) {
<a name="line355"></a>  var sb = [];
<a name="line356"></a>
<a name="line357"></a>  // Circular reference, certain functions like bind seem to cause a recursive
<a name="line358"></a>  // loop so we need to catch circular references
<a name="line359"></a>  if (goog.array.contains(visited, fn)) {
<a name="line360"></a>    sb.push(&#39;[...circular reference...]&#39;);
<a name="line361"></a>
<a name="line362"></a>  // Traverse the call stack until function not found or max depth is reached
<a name="line363"></a>  } else if (fn &amp;&amp; visited.length &lt; goog.debug.MAX_STACK_DEPTH) {
<a name="line364"></a>    sb.push(goog.debug.getFunctionName(fn) + &#39;(&#39;);
<a name="line365"></a>    var args = fn.arguments;
<a name="line366"></a>    for (var i = 0; i &lt; args.length; i++) {
<a name="line367"></a>      if (i &gt; 0) {
<a name="line368"></a>        sb.push(&#39;, &#39;);
<a name="line369"></a>      }
<a name="line370"></a>      var argDesc;
<a name="line371"></a>      var arg = args[i];
<a name="line372"></a>      switch (typeof arg) {
<a name="line373"></a>        case &#39;object&#39;:
<a name="line374"></a>          argDesc = arg ? &#39;object&#39; : &#39;null&#39;;
<a name="line375"></a>          break;
<a name="line376"></a>
<a name="line377"></a>        case &#39;string&#39;:
<a name="line378"></a>          argDesc = arg;
<a name="line379"></a>          break;
<a name="line380"></a>
<a name="line381"></a>        case &#39;number&#39;:
<a name="line382"></a>          argDesc = String(arg);
<a name="line383"></a>          break;
<a name="line384"></a>
<a name="line385"></a>        case &#39;boolean&#39;:
<a name="line386"></a>          argDesc = arg ? &#39;true&#39; : &#39;false&#39;;
<a name="line387"></a>          break;
<a name="line388"></a>
<a name="line389"></a>        case &#39;function&#39;:
<a name="line390"></a>          argDesc = goog.debug.getFunctionName(arg);
<a name="line391"></a>          argDesc = argDesc ? argDesc : &#39;[fn]&#39;;
<a name="line392"></a>          break;
<a name="line393"></a>
<a name="line394"></a>        case &#39;undefined&#39;:
<a name="line395"></a>        default:
<a name="line396"></a>          argDesc = typeof arg;
<a name="line397"></a>          break;
<a name="line398"></a>      }
<a name="line399"></a>
<a name="line400"></a>      if (argDesc.length &gt; 40) {
<a name="line401"></a>        argDesc = argDesc.substr(0, 40) + &#39;...&#39;;
<a name="line402"></a>      }
<a name="line403"></a>      sb.push(argDesc);
<a name="line404"></a>    }
<a name="line405"></a>    visited.push(fn);
<a name="line406"></a>    sb.push(&#39;)\n&#39;);
<a name="line407"></a>    /** @preserveTry */
<a name="line408"></a>    try {
<a name="line409"></a>      sb.push(goog.debug.getStacktraceHelper_(fn.caller, visited));
<a name="line410"></a>    } catch (e) {
<a name="line411"></a>      sb.push(&#39;[exception trying to get caller]\n&#39;);
<a name="line412"></a>    }
<a name="line413"></a>
<a name="line414"></a>  } else if (fn) {
<a name="line415"></a>    sb.push(&#39;[...long stack...]&#39;);
<a name="line416"></a>  } else {
<a name="line417"></a>    sb.push(&#39;[end]&#39;);
<a name="line418"></a>  }
<a name="line419"></a>  return sb.join(&#39;&#39;);
<a name="line420"></a>};
<a name="line421"></a>
<a name="line422"></a>
<a name="line423"></a>/**
<a name="line424"></a> * Set a custom function name resolver.
<a name="line425"></a> * @param {function(Function): string} resolver Resolves functions to their
<a name="line426"></a> *     names.
<a name="line427"></a> */
<a name="line428"></a>goog.debug.setFunctionResolver = function(resolver) {
<a name="line429"></a>  goog.debug.fnNameResolver_ = resolver;
<a name="line430"></a>};
<a name="line431"></a>
<a name="line432"></a>
<a name="line433"></a>/**
<a name="line434"></a> * Gets a function name
<a name="line435"></a> * @param {Function} fn Function to get name of.
<a name="line436"></a> * @return {string} Function&#39;s name.
<a name="line437"></a> */
<a name="line438"></a>goog.debug.getFunctionName = function(fn) {
<a name="line439"></a>  if (goog.debug.fnNameCache_[fn]) {
<a name="line440"></a>    return goog.debug.fnNameCache_[fn];
<a name="line441"></a>  }
<a name="line442"></a>  if (goog.debug.fnNameResolver_) {
<a name="line443"></a>    var name = goog.debug.fnNameResolver_(fn);
<a name="line444"></a>    if (name) {
<a name="line445"></a>      goog.debug.fnNameCache_[fn] = name;
<a name="line446"></a>      return name;
<a name="line447"></a>    }
<a name="line448"></a>  }
<a name="line449"></a>
<a name="line450"></a>  // Heuristically determine function name based on code.
<a name="line451"></a>  var functionSource = String(fn);
<a name="line452"></a>  if (!goog.debug.fnNameCache_[functionSource]) {
<a name="line453"></a>    var matches = /function ([^\(]+)/.exec(functionSource);
<a name="line454"></a>    if (matches) {
<a name="line455"></a>      var method = matches[1];
<a name="line456"></a>      goog.debug.fnNameCache_[functionSource] = method;
<a name="line457"></a>    } else {
<a name="line458"></a>      goog.debug.fnNameCache_[functionSource] = &#39;[Anonymous]&#39;;
<a name="line459"></a>    }
<a name="line460"></a>  }
<a name="line461"></a>
<a name="line462"></a>  return goog.debug.fnNameCache_[functionSource];
<a name="line463"></a>};
<a name="line464"></a>
<a name="line465"></a>
<a name="line466"></a>/**
<a name="line467"></a> * Makes whitespace visible by replacing it with printable characters.
<a name="line468"></a> * This is useful in finding diffrences between the expected and the actual
<a name="line469"></a> * output strings of a testcase.
<a name="line470"></a> * @param {string} string whose whitespace needs to be made visible.
<a name="line471"></a> * @return {string} string whose whitespace is made visible.
<a name="line472"></a> */
<a name="line473"></a>goog.debug.makeWhitespaceVisible = function(string) {
<a name="line474"></a>  return string.replace(/ /g, &#39;[_]&#39;)
<a name="line475"></a>      .replace(/\f/g, &#39;[f]&#39;)
<a name="line476"></a>      .replace(/\n/g, &#39;[n]\n&#39;)
<a name="line477"></a>      .replace(/\r/g, &#39;[r]&#39;)
<a name="line478"></a>      .replace(/\t/g, &#39;[t]&#39;);
<a name="line479"></a>};
<a name="line480"></a>
<a name="line481"></a>
<a name="line482"></a>/**
<a name="line483"></a> * Hash map for storing function names that have already been looked up.
<a name="line484"></a> * @type {Object}
<a name="line485"></a> * @private
<a name="line486"></a> */
<a name="line487"></a>goog.debug.fnNameCache_ = {};
<a name="line488"></a>
<a name="line489"></a>
<a name="line490"></a>/**
<a name="line491"></a> * Resolves functions to their names.  Resolved function names will be cached.
<a name="line492"></a> * @type {function(Function):string}
<a name="line493"></a> * @private
<a name="line494"></a> */
<a name="line495"></a>goog.debug.fnNameResolver_;
</pre>


</body>
</html>
